package com.module.record.controller;

import com.module.common.annotation.Log;
import com.module.common.core.controller.BaseController;
import com.module.common.core.domain.AjaxResult;
import com.module.common.core.page.TableDataInfo;
import com.module.common.enums.BusinessType;
import com.module.common.utils.DateUtils;
import com.module.common.utils.poi.ExcelUtil;
import com.module.record.domain.vo.RecordReadingVO;
import com.module.record.service.IRecordReadingService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 电表定时上传记录
 */
@Controller
@RequestMapping("/record/reading")
public class RecordReadingController extends BaseController {

    private String prefix = "record/reading";

    @Autowired
    private IRecordReadingService recordReadingService;

    @RequiresPermissions("record:reading:view")
    @GetMapping()
    public String reading(ModelMap mmap)
    {
        mmap.put("startDate", DateUtils.getDate());
        mmap.put("endDate", DateUtils.getDate());
        return prefix + "/reading";
    }

    /**
     * 查询采集设备列表
     */
    @RequiresPermissions("record:reading:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RecordReadingVO recordReadingVO)
    {
        List<RecordReadingVO> list = recordReadingService.selectRecordReadingList(recordReadingVO);
        return getDataTable(list);
    }

    /**
     * 定时上传记录
     * @param recordReadingVO
     * @return
     */
    @Log(title = "定时上传记录", businessType = BusinessType.EXPORT)
    @RequiresPermissions("record:reading:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RecordReadingVO recordReadingVO)
    {
        List<RecordReadingVO> list = recordReadingService.selectRecordReadingList(recordReadingVO);
        ExcelUtil<RecordReadingVO> util = new ExcelUtil<RecordReadingVO>(RecordReadingVO.class);
        return util.exportExcel(list, "定时上传记录");
    }
}
